package com.gzc.pm.util
{
	import com.gzc.pm.containers.BackgroundAlarmInfo;
	import com.gzc.pm.controls.LoadingUI;
	import com.gzc.pm.controls.PreLoadingUI;
	
	import flash.display.DisplayObject;
	
	import mx.collections.ArrayCollection;
	import mx.core.Application;
	import mx.managers.PopUpManager;

	public class PopUpUtil
	{
		public function PopUpUtil()
		{
		}
		
		public static var preLoading:PreLoadingUI;
		public static var loading:LoadingUI;
		public static var bgAlarmInfoWindow:BackgroundAlarmInfo;
		
		/**
		 * 显示preloading
		 */
		public static function showPreLoading():void{
			preLoading = PopUpManager.createPopUp(Application.application as DisplayObject,
				PreLoadingUI, false) as PreLoadingUI;
			PopUpManager.centerPopUp(preLoading);
		}
		
		/**
		 * 隐藏preloading
		 */
		public static function hidePreLoading():void{
			if(preLoading){
				PopUpManager.removePopUp(preLoading);
				preLoading = null;
			}
		}
		
		/**
		 * 显示loading
		 */
		public static function showLoading():void{
			loading = PopUpManager.createPopUp(Application.application as DisplayObject,
				LoadingUI, false) as LoadingUI;
			PopUpManager.centerPopUp(loading);
		}
		
		/**
		 * 隐藏loading
		 */
		public static function hideLoading():void{
			if(loading){
				PopUpManager.removePopUp(loading);
				loading = null;
			}
		}
		
		/**
		 * 显示背景告警信息
		 */
		public static function showBackgroundAlarm():void{
			bgAlarmInfoWindow = PopUpManager.createPopUp(Application.application as DisplayObject,
				BackgroundAlarmInfo, false) as BackgroundAlarmInfo;
			PopUpManager.centerPopUp(bgAlarmInfoWindow);
		}
		
		/**
		 * 设置背景告警信息
		 */
		public static function showBackgroundAlarmInfo(alarmInfoList:ArrayCollection):void{
			if(!bgAlarmInfoWindow){
				showBackgroundAlarm();
			}
			bgAlarmInfoWindow.alarmInfoList = alarmInfoList;
		}
		
		/**
		 * 隐藏背景告警信息
		 */
		public static function hideBackgroundAlarm():void{
			if(bgAlarmInfoWindow){
				PopUpManager.removePopUp(bgAlarmInfoWindow);
				bgAlarmInfoWindow = null;
			}
		}
		
	}
}